//
//  JGHistoryOrderController.m
//  JGRider
//
//  Created by 单启志 on 2018/1/25.
//  Copyright © 2018年 ffq. All rights reserved.
//

#import "JGHistoryOrderController.h"
#import "JGChooseDateView.h"
#import "JGHistoryOrderCell.h"
#import "JGOrderModel.h"
#import "JGOrderDetailsController.h"//订单详情
@interface JGHistoryOrderController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)JGChooseDateView *dateView;
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSArray *datas;
@end

@implementation JGHistoryOrderController
static NSString *cellId=@"historyOrderCell";
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSubViews];
}

-(void)configSubViews{
    self.title=@"历史订单";
    self.datas=[JGOrderModel models];
    [self.view addSubview:self.dateView];
    [self.view addSubview:self.tableView];
}

#pragma mark - override
-(UIImage *)lmjNavigationBarLeftButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar{

    return [UIImage imageNamed:@""];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - tableview delegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.datas.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

        return [tableView fd_heightForCellWithIdentifier:cellId configuration:^(JGHistoryOrderCell *cell) {
            cell.model=self.datas[indexPath.row];
        }];
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    JGHistoryOrderCell *cell=[tableView dequeueReusableCellWithIdentifier:cellId];
    cell.model=self.datas[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    JGOrderDetailsController *vc=[[JGOrderDetailsController alloc]init];
    JGpushViewController(vc);
}

#pragma mark - getter setter
-(UITableView *)tableView{

    if (!_tableView) {

        _tableView =[[UITableView alloc]initWithFrame:CGRectMake(0,self.lmj_navgationBar.height+self.dateView.height, JGScreenW, JGScreenH-self.lmj_navgationBar.height-self.dateView.height-self.tabBarController.tabBar.height) style:UITableViewStylePlain];

        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([JGHistoryOrderCell class]) bundle:nil] forCellReuseIdentifier:cellId];
        _tableView.backgroundColor=HEXCOLOR(0xf2f2f2);
        _tableView.showsVerticalScrollIndicator=NO; _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableView.delegate=self;
        _tableView.dataSource=self;
    }

    return _tableView;

}

-(JGChooseDateView *)dateView{

    if (!_dateView) {
        _dateView=[[JGChooseDateView alloc]initWithFrame:CGRectMake(0, self.lmj_navgationBar.height, JGScreenW, AdaptedHeight(57))];
    }
    return _dateView;
}

@end
